﻿using System;

namespace NetToolsV2
{
    public class IcmpEchoReply
    {
        private byte[] m_data;

        public IcmpEchoReply(int size) 
        {
            m_data = new byte[size];
        }

        public byte[] Buffer 
        { 
            get 
            {
                return m_data; 
            }
        }

        #region ICMP_ECHO_REPLY Structure
        public uint Address 
        { 
            get 
            { 
                return BitConverter.ToUInt32(m_data, 0); 
            } 
        }

        public uint Status 
        { 
            get 
            {
                return BitConverter.ToUInt32(m_data, 4); 
            } 
        }

        public uint RoundTripTime 
        { 
            get 
            {
                return BitConverter.ToUInt32(m_data, 8); 
            } 
        }

        public ushort DataSize 
        { 
            get 
            { 
                return BitConverter.ToUInt16(m_data, 0xc); 
            } 
            set 
            { 
                BitConverter.GetBytes(value).CopyTo(m_data, 0xc); 
            } 
        }

        public IntPtr Data 
        { 
            get 
            {
                return new IntPtr(BitConverter.ToInt32(m_data, 0x10)); 
            } 
            set 
            {
                BitConverter.GetBytes(value.ToInt32()).CopyTo(m_data, 0x10); 
            } 
        }

        public byte Ttl 
        { 
            get 
            { 
                return m_data[0x14]; 
            }
            set
            {
                m_data[0x14] = value;
            }
        }

        public byte Tos 
        { 
            get 
            { 
                return m_data[0x15]; 
            } 
        }

        public byte Flags 
        { 
            get 
            { 
                return m_data[0x16]; 
            } 
        }

        public byte OptionsSize 
        { 
            get 
            { 
                return m_data[0x17]; 
            } 
        }

        public IntPtr OptionsData 
        { 
            get 
            { 
                return new IntPtr(BitConverter.ToInt32(m_data, 0x18)); 
            } 
            set 
            { 
                BitConverter.GetBytes(value.ToInt32()).CopyTo(m_data, 0x18); 
            } 
        }

        #endregion
    }
}
